﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SysContext;

namespace DataAccessLayer
{
    public class CategoriesTable
    {
        SysDataContext Data = new SysDataContext();

        /// <summary>
        /// Thêm dữ liệu vào bảng Category
        /// </summary>
        /// <param name="Name"></param>
        /// <param name="GroudID"></param>
        /// <param name="Description"></param>
        public void InsertCAtegory(string Name, int GroudID, string Description)
        {
            Data.Insercategory(Name, GroudID, Description);
        }

        /// <summary>
        /// Lấy dữ liệu trong bảng Category
        /// </summary>
        /// <returns>Name</returns>
        public Array SelectName()
        {
            var Categories = (from c in Data.Categories
                             select c.Name).ToArray();
            return Categories.ToArray();
        }

        /// <summary>
        /// Lấy toàn bộ dữ liệu trong bảng Category
        /// </summary>
        /// <returns>Id,Name,Category_groupid</returns>
        public List<Category> Category()
        {
            var Categories = (from c in Data.Categories
                              select c).ToList();
            return Categories.ToList();
        }
        
        /// <summary>
        /// Lấy Id trong bảng Category
        /// </summary>
        /// <param name="name"></param>
        /// <returns>Id</returns>
        public double GetIdCategory(string name)
        {
            Category category = Data.Categories.Single(p => p.Name == name);
            return category.Id;
        }
    }
}
